package com.itheima.health.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.health.POJO.User;
import com.itheima.health.dao.UserDao;
import com.itheima.health.service.UserService;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl extends ServiceImpl<UserDao, User> implements UserService {
    /**
     * @description 用户登陆功能
     * @date 2021/11/29 10:53
     * @param user :
     * @return boolean
     */
    @Override
    public User login(String username,String password) {
        //1.获取用户名和密码
        //2.根据用户名查询有无用户
        LambdaQueryWrapper<User> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(User::getUsername,username);
        User one = getOne(wrapper);
        //无此用户
        if(null==one){
            return null;
        }
        if(!password.equals(one.getPassword())){
            return null;
        }
        //3.查询到用户判断密码是否匹配
        return one;
    }
}
